package ch.uzh.ifi.sonar;

import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

import ch.uzh.ifi.sonar.storage.PreferenceConstants;

public class QACPPPreferencePage extends FieldEditorPreferencePage implements
		IWorkbenchPreferencePage {

	private Composite fieldEditorParent;
	private IPreferenceStore store;

	public QACPPPreferencePage() {
		super(GRID);
		setPreferenceStore(Activator.getDefault().getPreferenceStore());
		setDescription("Here you can define the Sonar Qacpp Preferences");
		this.fieldEditorParent = getFieldEditorParent();
	}

	@Override
	public void init(IWorkbench workbench) {
		store = getPreferenceStore();
		store.setDefault(PreferenceConstants.QACPP_EXE_PATH,
				"C:\\\"Program Files\"\\PRQA\\QACPP-2.5.1-R\\bin\\qacpp.exe");
		store.setDefault(PreferenceConstants.PAL_EXE_PATH,
				"C:\\\"Program Files\"\\PRQA\\QACPP-2.5.1-R\\bin\\pal.exe");
		store.setDefault(PreferenceConstants.QACPP_SETTING_FILE_PATH,
				"D:\\sonar_workspace\\sonar_working_settings\\settings.via");
		store.setDefault(PreferenceConstants.SSQA_RESULT_PATH , "D:\\sonar_workspace\\sonar_working_output\\summary_result\\");
		store.setDefault(PreferenceConstants.STATIC_SUMMARY_FILE_NAME, "summary.csv");
	}
	
	@Override
	protected Control createContents(Composite parent) {
		fieldEditorParent = new Composite(parent, SWT.NULL);
		GridLayout layout = new GridLayout();
		layout.numColumns = 1;
		layout.marginHeight = 0;
		layout.marginWidth = 0;
		fieldEditorParent.setLayout(layout);
		fieldEditorParent.setFont(parent.getFont());

		createFieldEditors();
		initialize();
		checkState();
		return fieldEditorParent;
	}

	@Override
	protected void createFieldEditors() {
		addField(new StringFieldEditor(PreferenceConstants.QACPP_EXE_PATH,
				"&QACPP EXE file:", 60, fieldEditorParent));

		addField(new StringFieldEditor(PreferenceConstants.PAL_EXE_PATH,
				"&PAL EXE file:", 60, fieldEditorParent));

		addField(new StringFieldEditor(
				PreferenceConstants.QACPP_SETTING_FILE_PATH,
				"&SETTING VIA file:", 60, fieldEditorParent));
		
		addField(new StringFieldEditor(
				PreferenceConstants.SSQA_RESULT_PATH ,
				"&SSQA Summary Result Path:", 60, fieldEditorParent));
		addField(new StringFieldEditor(
				PreferenceConstants.STATIC_SUMMARY_FILE_NAME,
				"&SSQA Summary Result csv:", 60, fieldEditorParent));

	}

}
